package com.fc.test.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fc.test.mapper.auto.TAbbGuanyuMapper;
import com.fc.test.mapper.auto.TAbbMianzeMapper;
import com.fc.test.model.auto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.TAbbJiangjieMapper;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 * Service
* @Title: TAbbJiangjieService.java 
* @Package com.fc.test.entity 
* @author fuce
* @email 87766867@qq.com
* @date 2019-08-13 08:47:01  
 */
@Service
public class TAbbJiangjieService implements BaseService<TAbbJiangjie, TAbbJiangjieExample>{
	@Autowired
	private TAbbJiangjieMapper tAbbJiangjieMapper;

	@Autowired
	private TAbbMianzeMapper mianzeMapper;

	@Autowired
	private TAbbGuanyuMapper guanyuMapper;
	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<TAbbJiangjie> list(Tablepar tablepar){
	        TAbbJiangjieExample testExample=new TAbbJiangjieExample();
	        testExample.setOrderByClause("id ASC");

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<TAbbJiangjie> list= tAbbJiangjieMapper.selectByExample(testExample);
	        PageInfo<TAbbJiangjie> pageInfo = new PageInfo<TAbbJiangjie>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
		List<String> lista=Convert.toListStrArray(ids);
		TAbbJiangjieExample example=new TAbbJiangjieExample();
		example.createCriteria().andIdIn(lista);
		return tAbbJiangjieMapper.deleteByExample(example);
	}
	
	
	@Override
	public TAbbJiangjie selectByPrimaryKey(String id) {
		
		return tAbbJiangjieMapper.selectByPrimaryKey(id);
	}

	
	@Override
	public int updateByPrimaryKeySelective(TAbbJiangjie record) {
		return tAbbJiangjieMapper.updateByPrimaryKeySelective(record);
	}
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(TAbbJiangjie record) {
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
		return tAbbJiangjieMapper.insertSelective(record);
	}
	
	

	

	
	
	

	
	@Override
	public int updateByExampleSelective(TAbbJiangjie record, TAbbJiangjieExample example) {
		
		return tAbbJiangjieMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(TAbbJiangjie record, TAbbJiangjieExample example) {
		
		return tAbbJiangjieMapper.updateByExample(record, example);
	}

	@Override
	public List<TAbbJiangjie> selectByExample(TAbbJiangjieExample example) {
		
		return tAbbJiangjieMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(TAbbJiangjieExample example) {
		
		return tAbbJiangjieMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(TAbbJiangjieExample example) {
		
		return tAbbJiangjieMapper.deleteByExample(example);
	}
	

	public Map<String,Object> getArticleInfo(int type){
		Map<String,Object> resMap = new HashMap<>();
		if(type==1){
			TAbbJiangjieExample testExample=new TAbbJiangjieExample();
			testExample.setOrderByClause("id ASC");
			PageHelper.startPage(1, 1);
			List<TAbbJiangjie> list= tAbbJiangjieMapper.selectByExample(testExample);
			if(list.size()>0){
				TAbbJiangjie jiangjie = list.get(0);
				resMap.put("data",jiangjie);
				resMap.put("msg","获取使用教程成功");
				resMap.put("success",true);
			}else{
				resMap.put("msg","没有使用教程");
				resMap.put("success",false);
			}
		}else if(type==2){
			TAbbGuanyuExample testExample=new TAbbGuanyuExample();
			testExample.setOrderByClause("id ASC");
			PageHelper.startPage(1, 1);
			List<TAbbGuanyu> list= guanyuMapper.selectByExample(testExample);
			if(list.size()>0){
				TAbbGuanyu guanyu = list.get(0);
				resMap.put("data",guanyu);
				resMap.put("msg","获取关于我们成功");
				resMap.put("success",true);
			}else{
				resMap.put("msg","没有关于我们");
				resMap.put("success",false);
			}
		}else if(type==3){
			TAbbMianzeExample testExample=new TAbbMianzeExample();
			testExample.setOrderByClause("id ASC");
			PageHelper.startPage(1, 1);
			List<TAbbMianze> list= mianzeMapper.selectByExample(testExample);
			if(list.size()>0){
				TAbbMianze mianze = list.get(0);
				resMap.put("data",mianze);
				resMap.put("msg","获取免责声明成功");
				resMap.put("success",true);
			}else{
				resMap.put("msg","没有免责声明");
				resMap.put("success",false);
			}
		}
		return resMap;
	}


}
